def run(params:list[str]):
    import os
    from ApiTools import apiTools,apiBase,LangGraphState
    from typing_extensions import TypedDict
    from langgraph.graph import END, StateGraph, START

    # 输入hpl目录,里面固定有start和flow控制实现muti-agent ,不需要通过json来配置
    dir=apiBase.argv(1,'$PROJECT_HOME/88api/graphbyhpl/') 
    # 提示词
    prompt=apiBase.argv_json(2,{"aggregate": [], "curNodeName": "start"})

    with open(dir + "/conditional.py", 'r', encoding='utf-8') as file:
        code=file.read()
        exec(code)
        # 创建条件函数
        conditional = eval('conditional')
                        
    def should_loop(state: LangGraphState):
        sz=len(state['aggregate']) 
        if sz > 0:
            curNodeName = state['aggregate'][sz-1]
        else:
            curNodeName =state['curNodeName']
        #print(f"should_loop->curNodeName= {curNodeName}")
        nextNodeName = conditional(curNodeName)
        if nextNodeName == "__end__":
            return END
        return nextNodeName


    # 加载节点
    node_tools = {}
    folder_names = os.listdir(dir)
    for file in folder_names:
        ph=dir + "/" + file
        if os.path.isfile(ph):
            apiTools.load_langgraph_node(node_tools,dir, file)

    try:
        builder = StateGraph(LangGraphState)
        for name in node_tools:
            builder.add_node(name, node_tools[name])
            builder.add_conditional_edges(
                name,
                should_loop,
            )
        builder.add_edge(START, "start")
        graph = builder.compile()
        res=graph.invoke(prompt)
        #res=graph.invoke({"aggregate": [], "curNodeName": "bc"})
        print(res)
    finally:   
        apiBase.close()